package _1_LabelAndButton;

import java.awt.Container;

import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;

public class TImageButton {

    private JFrame frame = null;
    
    private JButton button1 = null;
    
    private JButton button2 = null;
    
    private JButton button3 = null;
    
    public TImageButton() {
        Container contentPane = null;
        frame = new JFrame("image button test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        contentPane=frame.getContentPane();
        contentPane.add(initButtons());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
    
    private JComponent initButtons() {
        button1 = new JButton();
        button1.setIcon(new ImageIcon("res\\selector_game_normal.png"));
        button1.setSelectedIcon(new ImageIcon("res\\selector_game_focus.png"));
        button1.setRolloverIcon(new ImageIcon("res\\selector_game_focus.png"));
        button1.setPressedIcon(new ImageIcon("res\\selector_game_pressed.png"));
        setImageButtonStyle(button1);
        
        button2 = new JButton();
        button2.setIcon(new ImageIcon("res\\selector_live_normal.png"));
        button2.setSelectedIcon(new ImageIcon("res\\selector_live_focus.png"));
        button2.setRolloverIcon(new ImageIcon("res\\selector_live_focus.png"));
        button2.setPressedIcon(new ImageIcon("res\\selector_live_pressed.png"));
        setImageButtonStyle(button2);
        
        button3 = new JButton();
        button3.setIcon(new ImageIcon("res\\selector_recommand_normal.png"));
        button3.setSelectedIcon(new ImageIcon("res\\selector_recommand_focus.png"));
        button3.setRolloverIcon(new ImageIcon("res\\selector_recommand_focus.png"));
        button3.setPressedIcon(new ImageIcon("res\\selector_recommand_pressed.png"));
        setImageButtonStyle(button3);
        
        Box buttonBox = Box.createHorizontalBox();
        buttonBox.add(Box.createHorizontalGlue());
        buttonBox.add(Box.createHorizontalStrut(20));
        buttonBox.add(button1);
        buttonBox.add(Box.createHorizontalStrut(20));
        buttonBox.add(button2);
        buttonBox.add(Box.createHorizontalStrut(20));
        buttonBox.add(button3);
        buttonBox.add(Box.createHorizontalStrut(20));
        buttonBox.add(Box.createHorizontalGlue());
        return buttonBox;
    }
    
    private void setImageButtonStyle(JButton button) {
        button.setUI(new ImageButtonUI());
        button.setOpaque(false);
        button.setContentAreaFilled(false);
        button.setFocusPainted(false);
        button.setBorder(null);
        System.out.println(button.getUI());
    }

    public static void main(String[] args) {
        new TImageButton();
    }
}
